#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include "Device.h"
#include "window.h"
#include "SpriteMgr.h"

#define FVF (D3DFVF_XYZRHW | D3DFVF_TEX1)
Device::Device()
{
	g_pD3D = Direct3DCreate9( D3D_SDK_VERSION);

	SetRect(&MainScreenRt,0,0,1024,512);
}
Device::~Device()
{
	if(g_pD3D != NULL)
		g_pD3D->Release();

	if(g_pd3dDevice != NULL)
		g_pd3dDevice->Release();
}
void Device::Initialize(HWND m_hWnd)
{
	ZeroMemory(&d3dpp,sizeof(d3dpp));
	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	d3dpp.hDeviceWindow = m_hWnd;

	g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,
		D3DDEVTYPE_HAL,m_hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&d3dpp,&g_pd3dDevice);

	SpMgr = new SpriteMgr(this);

	D3DXCreateTextureFromFile(g_pd3dDevice,"MainScreen.png",&Texture1);
}
void Device::Render()
{
	SpMgr->vBegin();
	SpMgr->vRender(Texture1,&MainScreenRt);
	SpMgr->vEnd();
}